import { Event } from "../app_base/base/event/Event";

const { ccclass, property, disallowMultiple, menu } = cc._decorator;



enum Easing {
    quadIn = 0,
    quadOut = 1,
    quadInOut = 2,
}

const easingArr: string[] = [
    "quadIn",
    "quadOut",
    "quadInOut",
]


enum test {
    // Easing[Easing["quadIn"] = 0] = "quadIn";
    // Easing[Easing["quadOut"] = 1] = "quadOut";
    // Easing[Easing["quadInOut"] = 2] = "quadInOut";
    // Easing[Easing["cubicIn"] = 3] = "cubicIn";
    // Easing[Easing["cubicOut"] = 4] = "cubicOut";
    // Easing[Easing["cubicInOut"] = 5] = "cubicInOut";
    // Easing[Easing["quartIn"] = 6] = "quartIn";
    // Easing[Easing["quartOut"] = 7] = "quartOut";
    // Easing[Easing["quartInOut"] = 8] = "quartInOut";
    // Easing[Easing["quintIn"] = 9] = "quintIn";
    // Easing[Easing["quintOut"] = 10] = "quintOut";
    // Easing[Easing["quintInOut"] = 11] = "quintInOut";
    // Easing[Easing["sineIn"] = 12] = "sineIn";
    // Easing[Easing["sineOut"] = 13] = "sineOut";
    // Easing[Easing["sineInOut"] = 14] = "sineInOut";
    // Easing[Easing["expoIn"] = 15] = "expoIn";
    // Easing[Easing["expoOut"] = 16] = "expoOut";
    // Easing[Easing["expoInOut"] = 17] = "expoInOut";
    // Easing[Easing["circIn"] = 18] = "circIn";
    // Easing[Easing["circOut"] = 19] = "circOut";
    // Easing[Easing["circInOut"] = 20] = "circInOut";
    // Easing[Easing["elasticIn"] = 21] = "elasticIn";
    // Easing[Easing["elasticOut"] = 22] = "elasticOut";
    // Easing[Easing["elasticInOut"] = 23] = "elasticInOut";
    // Easing[Easing["backIn"] = 24] = "backIn";
    // Easing[Easing["backOut"] = 25] = "backOut";
    // Easing[Easing["backInOut"] = 26] = "backInOut";
    // Easing[Easing["bounceIn"] = 27] = "bounceIn";
    // Easing[Easing["bounceOut"] = 28] = "bounceOut";
    // Easing[Easing["bounceInOut"] = 29] = "bounceInOut";
    // Easing[Easing["smooth"] = 30] = "smooth";
    // Easing[Easing["fade"] = 31] = "fade";
}


@ccclass
@disallowMultiple()
@menu('自定义组件/ScaleAnimation')
export class ScaleAnimation extends cc.Component {
    /**
     * 起始Scale值
     */
    @property({ type: cc.Float, tooltip: "起始Scale值" })
    private from = 0;
    /**
     * 动画时长
     */
    @property({ type: cc.Float, tooltip: "动画时长" })
    private duration = 0;
    /**
     * 缓动类型
     */
    @property({ type: cc.Enum(Easing), tooltip: "缓动参数,参考cc.easing.xxx" })
    private easing: Easing = Easing.quadIn;

    private _initScale = 0;

    constructor() {
        super();
        this.from = 0.6
        this.duration = 0.3;
        this.easing = Easing.quadIn;
    }

    protected onLoad() {
        this._initScale = this.node.scale;
    }

    protected onEnable() {
        var _this = this;
        console.log("from:", this.from, "duration:", this.duration);
        cc.Tween.stopAllByTarget(this.node);
        cc.tween(this.node).set({ scale: this.from * this._initScale })
            .to(this.duration, { scale: this._initScale }, { easing: easingArr[this.easing] })
            .call(function () {
                _this.node.dispatchEvent(new cc.Event(Event.COMPLETE, true));
            }).start();
    }



}
